Imports System.Data.SqlClient

Public Class adm_findusers
    Inherits System.Web.UI.Page
    'Protected WithEvents TheHeader1 As adm_header
    Public Msg, target, sortby, sPin As String
    Public aUserSession(13) As String
    'Public oUtils As utils
    Public bLocked As Boolean
    Public nTempRPP, i As Integer
    Public Const cSESSION_ID = 0
    Public Const cCOMPANY_ID = 1
    Public Const cGAPORTAL_ID = 2
    Public Const cUSER_ID = 3
    Public Const cINCIDCONTEXT = 4
    Public Const cINGIDCONTEXT = 5
    Public Const cLOGINDATETIME = 6
    Public Const cLASTACTIVITY = 7
    Public Const cUSERPERMISSIONSSTRING = 8
    'Public Const cTERMINAL_PIN = 9
    Public Const cROLE_ID = 9
    Public Const cMEMBER_TYPE = 10
    'Public Const cTERMINAL_NAME = 10
    Public Const cTERMINAL_NUMBER = 11
    Public Const cTERMINAL_MARKET = 12
    Public UID, CID, CompanyID As String
    Public sQS, PG, HTMLString, HTMLDispage, HTMLMertList As String
    Public nNumPages, FilteredPG As Integer
    Public vRs As DataView

    Public FilteredUID As String
    Public FilteredCID As String
    Public FilteredVID As String
    Public Filteredfirstname As String
    Public Filteredlastname As String
    Public Filteredlocation As String
    Public FilteredRPP As String
    Public Filteredsortby As String
    'Public FilteredUID As String
    'Public FilteredUID As String
    Public bgcolor As String = "294984"
    Protected WithEvents vid As System.Web.UI.WebControls.TextBox
    Protected WithEvents dropCID As System.Web.UI.WebControls.DropDownList
    Protected WithEvents sVID As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtFname As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtLname As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtLoc As System.Web.UI.WebControls.TextBox
    Protected WithEvents RPP As System.Web.UI.WebControls.DropDownList
    Protected WithEvents btnFind As System.Web.UI.WebControls.Button
    Protected WithEvents btnCancel As System.Web.UI.WebControls.Button
    Dim ToggleSort As Boolean = True
    Public objvalid As gaValidation = New gaValidation
    Public imgpath, currtURL As String
    'Dim objfind As UserManagement.UserManagement
    Dim ToggleSortOrder As Boolean

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        objvalid.getURL(Request.Url.ToString, imgpath, currtURL)
        BuildComplist()
        BuildRPP()
    End Sub
    Private Sub BuildComplist()
        Dim objdata As gaValidation
        objdata = New gaValidation
        dropCID.Items.Clear()
        dropCID.DataSource = objdata.GetCompany("000000", "0")
    End Sub
    Private Sub BuildRPP()
        Dim i As Integer
        ''RPP.Items.Add(New ListItem("M", "115"))
        If Not IsPostBack Then
            nTempRPP = 0
            RPP.Items.Clear()
            For i = 1 To 4
                RPP.Items.Add(New ListItem(i * 25, i))
            Next
            RPP.SelectedIndex = 0
        Else
            If CInt(Request("RPP")) > 0 Then
                nTempRPP = CInt(Request("RPP"))
            End If
            For i = 1 To 4 Step 1
                If nTempRPP = i * 25 Then
                    RPP.SelectedItem.Text = nTempRPP
                    Exit For
                End If
            Next
        End If

    End Sub
    Public Function DrawPaginationControls() As String
        Dim strPageNum As String = ""
        'If 'Request("sortby").count > 0 Then
        'sQS = sQS & "&sortby=" & Request("sortby")
        'End If
        strPageNum = "<table class=""pos""><tr>"

        If FilteredPG > 1 Then
            strPageNum += "<td align=""left""><font face=""arial"" size=""2"">"
            strPageNum += "	<a href=""adm_findusers.asp<%=sQS%>&action=Refind&PG=<%=FilteredPG - 1%>""><b>PREVIOUS PAGE</b></a></font></td>"

        End If
        strPageNum += "<td><font face=""arial"" size=2>&nbsp;</font></td><td>"

        strPageNum += "<font face=""arial"" size=2>Displaying Page <%=FilteredPG%> of <%=nNumPages%>.</font></td><td><font face=""arial"" size=2>&nbsp;</font></td>"

        If nNumPages > FilteredPG Then
            strPageNum += "<td align=""right"">"
            strPageNum += "	<font face=""arial"" size=""2""><a href=""adm_findusers.asp<%=sQS%>&action=Refind&PG=<%=FilteredPG + 1%>""><b>NEXT PAGE</b></a></font></td>"


        End If
        strPageNum += "</tr></table>"
        DrawPaginationControls = strPageNum
        'Return HTMLDispage
        '        <%	sub drawPaginationControls %>
        '		<table class="pos">
        '		<tr>
        '	 <%		if FilteredPG > 1 then %>
        '		<td align="left">
        '			<font face="arial" size=2><a href="adm_findusers.asp<%=sQS%>&action=Refind&PG=<%=FilteredPG - 1%>"><b>PREVIOUS PAGE</b></a>
        '			</font>
        '		</td>
        ' <%		end if %>
        '		<td>
        '			<font face="arial" size=2>&nbsp;
        '			</font>
        '		</td><td>
        '			<font face="arial" size=2>Displaying Page <%=FilteredPG%> of <%=nNumPages%>.
        '			</font>
        '		</td><td>
        '			<font face="arial" size=2>&nbsp;
        '			</font>
        '		</td>
        '   <%	if nNumPages > FilteredPg then %>
        '		<td align="right">
        '			<font face="arial" size=2><a href="adm_findusers.asp<%=sQS%>&action=Refind&PG=<%=FilteredPG + 1%>"><b>NEXT PAGE</b></a>
        '			</font>
        '		</td>
        '  <%	end if %>
        '		</tr>
        '		</table>
        '<%	end sub %>
    End Function
    ' Public Function GetData(ByVal v As DataView) As String
    'For colctr = 0 To UBound(vRs, 2)
    '    companyname = vRs(0, colctr)
    '    UID = vRs(1, colctr)
    '    CID = vRs(2, colctr)
    '    vid = vRs(3, colctr)
    '    firstname = vRs(4, colctr)
    '    lastname = vRs(5, colctr)
    '    location = vRs(6, colctr)
    '    supervisor = vRs(7, colctr)
    '    active = vRs(8, colctr)
    '    HTMLString = HTMLString & vbCr & vbTab & vbTab & "<tr bgcolor=""" & bgcolor & """>"
    '    If aUserSession(cCOMPANY_ID) = "0" Then
    '        HTMLString = HTMLString & "<td valign=""top""><a href=""javascript:userdetail('" & UID & "','" & CID & "','" & vid & "')"">" & UID & "</a>&nbsp;</td>"
    '    Else
    '        HTMLString = HTMLString & "<td valign=""top""><a href=""javascript:userdetail('" & UID & "',' ','" & vid & "')"">" & UID & "</a>&nbsp;</td>"
    '    End If
    '    If aUserSession(cCOMPANY_ID) = "0" Then
    '        HTMLString = HTMLString & "<td valign=""top"">" & companyname & "&nbsp;</td>"
    '    End If

    '    HTMLString = HTMLString & "<td valign=""top"">" & vid & "&nbsp;</td>"

    '    HTMLString = HTMLString & "<td valign=""top"">" & firstname & "&nbsp;</td>"
    '    HTMLString = HTMLString & "<td valign=""top"">" & lastname & "&nbsp;</td>"
    '    HTMLString = HTMLString & "<td valign=""top"">" & location & "&nbsp;</td>"
    '    HTMLString = HTMLString & "<td valign=""top"">" & supervisor & "&nbsp;</td>"
    '    HTMLString = HTMLString & "<td valign=""top"">" & UCase(active) & "&nbsp;</td>"

    'Next
    'HTMLString = HTMLString & "</tr>"
    'End Function
    Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
        Dim strHtml As String = ""
        Dim colctr As Integer
        Dim strUID, supervisor As String
        Dim firstname, lastname, location As String
        Dim active As String
        Dim Rs As New DataSet
        Dim strTDError As String = ""
        strUID = vid.Text
        firstname = txtFname.Text
        lastname = txtLname.Text
        location = txtLoc.Text
        FilteredRPP = RPP.Text
        Dim sSQL As String

        sSQL = "SELECT "
        sSQL = sSQL & "adminuser_id, "
        sSQL = sSQL & "first_name, "
        sSQL = sSQL & "last_name, "
        sSQL = sSQL & "location, "
        sSQL = sSQL & "supervisor, "
        sSQL = sSQL & "active "
        sSQL = sSQL & "FROM "
        sSQL = sSQL & "adm_user where 1=1"

        If strUID <> "" Then
            sSQL = sSQL & " and Upper(adminuser_id) like '%" & UCase(strUID) & "%'"
        End If
        If lastname <> "" Then
            sSQL = sSQL & " and Upper(last_name) like '%" & UCase(lastname) & "%'"
        End If

        If firstname <> "" Then
            sSQL = sSQL & " and Upper(first_name) like '%" & UCase(firstname) & "%'"
        End If
        If location <> "" Then
            sSQL = sSQL & " and Upper(location) like '%" & UCase(location) & "%'"
        End If

        Dim objfind As New GetData
        Dim objrd As SqlDataReader = Nothing

        objfind.Dataset(sSQL, "adminuser", strTDError, Rs)


        If Rs.Tables(0).Rows.Count = 0 Then
            strHtml = "No users were found"

        Else
            strHtml += "<table class='minorbox' cellspacing='0' width='100%'>"
            strHtml += "<tr	><td class='gridheader'>User ID</td>"

            strHtml += "<td class='gridheader'>First Name</td>"

            strHtml += "<td class='gridheader'>Last Name</td>"

            strHtml += "<td class='gridheader'>Location</td>"

            strHtml += "<td class='gridheader'>Supervisor</td>"

            strHtml += "<td class='gridheader'>Active</td></tr>"

            For colctr = 0 To Rs.Tables(0).Rows.Count - 1

                strUID = Rs.Tables(0).Rows(colctr).Item("adminuser_id")
                firstname = Rs.Tables(0).Rows(colctr).Item("first_name")
                lastname = Rs.Tables(0).Rows(colctr).Item("last_name")
                location = Rs.Tables(0).Rows(colctr).Item("location")
                supervisor = Rs.Tables(0).Rows(colctr).Item("supervisor")
                active = Rs.Tables(0).Rows(colctr).Item("active")
                HTMLString = HTMLString & vbCr & vbTab & vbTab & "<tr bgcolor=""" & bgcolor & """>"
                HTMLString = HTMLString & "<td valign=""top"">" & strUID & "&nbsp;</td>"
                HTMLString = HTMLString & "<td valign=""top"">" & firstname & "&nbsp;</td>"
                HTMLString = HTMLString & "<td valign=""top"">" & lastname & "&nbsp;</td>"
                HTMLString = HTMLString & "<td valign=""top"">" & location & "&nbsp;</td>"
                HTMLString = HTMLString & "<td valign=""top"">" & supervisor & "&nbsp;</td>"
                HTMLString = HTMLString & "<td valign=""top"">" & UCase(active) & "&nbsp;</td></tr>"

            Next
            HTMLString = HTMLString & "</table>"
            ' Response.Write(HTMLString)
            strHtml += HTMLString

        End If

    End Sub

    'Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
    '    Dim strHtml As String = ""
    '    Dim colctr As Integer
    '    Dim companyname, UID, VID As String
    '    Dim CID, supervisor As String
    '    Dim firstname, lastname, location As String
    '    Dim active As String
    '    Dim vRs As DataSet
    '    Dim objfind As New UserManagement.UserManagement

    '    FilteredUID = Trim(Request("sUID"))
    '    FilteredCID = Trim(Request("sCID"))
    '    FilteredVID = Trim(Request("sVID"))
    '    Filteredfirstname = Trim(Request("firstname"))
    '    Filteredlastname = Trim(Request("lastname"))
    '    Filteredlocation = Trim(Request("location"))
    '    FilteredRPP = CInt(Request("RPP"))
    '    FilteredPG = CInt(Request("PG"))
    '    Filteredsortby = Trim(Request("sortby"))

    '    sQS = "?sUID=" & Server.UrlEncode(FilteredUID)
    '    If aUserSession(cCOMPANY_ID) = "0" Then
    '        sQS = sQS & "&sCID=" & Server.UrlEncode(FilteredCID)
    '    End If
    '    sQS = sQS & "&sVID=" & Server.UrlEncode(FilteredVID)
    '    sQS = sQS & "&firstname=" & Server.UrlEncode(Filteredfirstname)
    '    sQS = sQS & "&lastname=" & Server.UrlEncode(Filteredlastname)
    '    sQS = sQS & "&location=" & Server.UrlEncode(Filteredlocation)
    '    sQS = sQS & "&RPP=" & Server.UrlEncode(FilteredRPP)
    '    ''//find users
    '    'ofinduser = Server.CreateObject("viaUserManagement.UserManagement")

    '    objfind.DBConnectstring = Application("DSN")
    '    'objfind.DBConnectstring = "Data Source=(Local); Initial Catalog=gaglobal10;Trusted_Connection=true;"
    '    objfind.nPage = FilteredPG
    '    objfind.nPageRecords = FilteredRPP
    '    If aUserSession(cCOMPANY_ID) = "0" And FilteredCID = "" Then
    '        FilteredCID = -1
    '    ElseIf aUserSession(cCOMPANY_ID) = "0" Then
    '        FilteredCID = CInt(FilteredCID)
    '    Else
    '        FilteredCID = CInt(Application("CompanyID"))
    '    End If

    '    vRs = New DataSet
    '    If Request("action") = "Find" Then
    '        ToggleSortOrder = False

    '    Else
    '        ToggleSortOrder = True
    '    End If
    '    objfind.SessionID = Session("UserSession")
    '    'vRs = objfind.FindUsers(FilteredUID, FilteredCID, FilteredVID, Filteredlastname, Filteredfirstname, Filteredlocation, Filteredsortby, ToggleSortOrder)
    '    nNumPages = objfind.nNumPages
    '    'ofinduser = Nothing
    '    If vRs.Tables(0).Rows.Count = 0 Then
    '        strHtml = "<tr><td class='header'>No users were found</td></tr>"

    '    Else
    '        strHtml += "<tr><td class='header'>Search Results</td></tr><tr><td><table class='minorbox' cellspacing='0' width='100%'>"
    '        strHtml += "<tr	><td class='gridheader'> <a href='adm_findusers.asp<%=sQS%>&action=Refind&sortby=UID&PG=<%=request(""PG"")%>'>User ID</a></td>"

    '        If aUserSession(cCOMPANY_ID) = "0" Then
    '            strHtml += "<td class='gridheader'><a href='adm_findusers.asp<%=sQS%>&action=Refind&sortby=COMPANYNAME&PG=<%=request('PG')%>'>System Name</a></td>"

    '        End If

    '        strHtml += "<td class='gridheader'><a href='adm_findusers.asp<%=sQS%>&action=Refind&sortby=VID&PG=<%=request('PG')%>'>Account ID</a></td>"


    '        strHtml += "<td class='gridheader'><a href='adm_findusers.asp<%=sQS%>&action=Refind&sortby=FIRSTNAME&PG=<%=request('PG')%>'>First Name</a></td>"

    '        strHtml += "<td class='gridheader'><a href='adm_findusers.asp<%=sQS%>&action=Refind&sortby=LASTNAME&PG=<%=request('PG')%>'>Last Name</a></td>"

    '        strHtml += "<td class='gridheader'><a href='adm_findusers.asp<%=sQS%>&action=Refind&sortby=LOCATION&PG=<%=request('PG')%>'>Location</a></td>"

    '        strHtml += "<td class='gridheader'><a href='adm_findusers.asp<%=sQS%>&action=Refind&sortby=SUPERVISOR&PG=<%=request('PG')%>'>Supervisor</a></td>"

    '        strHtml += "<td class='gridheader'><a href='adm_findusers.asp<%=sQS%>&action=Refind&sortby=ACTIVE&PG=<%=request('PG')%>'>Active</a></td></tr>"

    '        For colctr = 0 To vRs.Tables(0).Rows.Count - 1
    '            companyname = vRs.Tables(0).Rows(colctr).Item(0)
    '            UID = vRs.Tables(0).Rows(colctr).Item(1)
    '            CID = vRs.Tables(0).Rows(colctr).Item(2)
    '            VID = vRs.Tables(0).Rows(colctr).Item(3)
    '            firstname = vRs.Tables(0).Rows(colctr).Item(4)
    '            lastname = vRs.Tables(0).Rows(colctr).Item(5)
    '            location = vRs.Tables(0).Rows(colctr).Item(6)
    '            supervisor = vRs.Tables(0).Rows(colctr).Item(7)
    '            active = vRs.Tables(0).Rows(colctr).Item(8)
    '            HTMLString = HTMLString & vbCr & vbTab & vbTab & "<tr bgcolor=""" & bgcolor & """>"
    '            If aUserSession(cCOMPANY_ID) = "0" Then
    '                HTMLString = HTMLString & "<td valign=""top""><a href=""javascript:userdetail('" & UID & "','" & CID & "','" & VID & "')"">" & UID & "</a>&nbsp;</td>"
    '            Else
    '                HTMLString = HTMLString & "<td valign=""top""><a href=""javascript:userdetail('" & UID & "',' ','" & VID & "')"">" & UID & "</a>&nbsp;</td>"
    '            End If
    '            If aUserSession(cCOMPANY_ID) = "0" Then
    '                HTMLString = HTMLString & "<td valign=""top"">" & companyname & "&nbsp;</td>"
    '            End If

    '            HTMLString = HTMLString & "<td valign=""top"">" & VID & "&nbsp;</td>"

    '            HTMLString = HTMLString & "<td valign=""top"">" & firstname & "&nbsp;</td>"
    '            HTMLString = HTMLString & "<td valign=""top"">" & lastname & "&nbsp;</td>"
    '            HTMLString = HTMLString & "<td valign=""top"">" & location & "&nbsp;</td>"
    '            HTMLString = HTMLString & "<td valign=""top"">" & supervisor & "&nbsp;</td>"
    '            HTMLString = HTMLString & "<td valign=""top"">" & UCase(active) & "&nbsp;</td>"

    '        Next
    '        HTMLString = HTMLString & "</tr>"
    '        ' Response.Write(HTMLString)
    '        strHtml += HTMLString
    '        If Not IsNothing(Request("sortby")) Then
    '            sQS = sQS & "&sortby=" & Request("sortby")
    '        End If
    '        strHtml += "</table></td></tr><tr><td align='center'>"

    '        strHtml += DrawPaginationControls()
    '        strHtml += "</td></tr>"

    '    End If

    '    strHtml += "<input type='hidden' name='uid'>"
    '    strHtml += "<input type='hidden' name='vid'>"
    '    strHtml += "<input type='hidden' name='cid'>"
    '    Response.Write(strHtml)
    'End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("../UserMngt/UserMngt_default.aspx")
    End Sub

    Private Sub RPP_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RPP.SelectedIndexChanged
        '    nTempRPP = 0
        '   If Request("RPP").count > 0 Then
        '       nTempRPP = CInt(Request("RPP"))
        '   End If

        '   For i = 1 To 4 Step 1
        '	if nTempRPP = i * 25 then %>
        '	<option selected="true"><%=i*25%></option>
        '	<%else %>
        '	<option><%=i*25%></option>
        ' <%
        '	 end if
        '   Next
        '%>
        '</select>
    End Sub

    Protected Sub vid_TextChanged(sender As Object, e As EventArgs)

    End Sub
End Class
